<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>用户管理</title>
		<%@include file="/WEB-INF/ibnms/common/jqgrid.jsp"%>
		<%@ include file="/WEB-INF/ibnms/common/formValidation.jsp"%>
        <jsp:include page="/WEB-INF/ibnms/common/configinclude.jsp"></jsp:include>
		<script language="javascript">
			$(function(){
               //$("select[multiple='multiple']").multiselect();
            });

	function checkValid(obj){

		if (!checkEmpty(obj.userCode,'登录名')) return false;
		if (!checkEmpty(obj.userName,'用户姓名')) return false;
		var a1 = Trim(obj.password.value);
		var a2 = Trim(obj.confirmPassword.value);
		if(a1 != a2 ) {
			alert("两次输入的密码不一致！");
			return false;
		}
         if(a1.length < 8 ) {
			alert("输入的密码不足8位！");
			return false;
		}   
		 if(a2.length < 8 ) {
			alert("输入的密码不足8位！");
			return false;
		}                           
        if(isdigit(obj.telphone.value)==0){
                       alert("联系电话号含有非法数字")                                     
                       return false;
                     }
		if (!checkEmpty(obj.email,'Email')) return false;
		if (obj.alreadySelect.length < 1){
			alert("未指定角色！");
			return false;
		}
		return true;
	}
	 function isdigit(s)
            {
            var r,re;
            re = /\d*/i; //\d表示数字,*表示匹配多个数字
            r = s.match(re);
            return (r==s)?1:0;
            }
</script>
</head>

<body>
<div class="form-wrapper">
    	<div class="form-title">
       		 <span class="ttcorner"></span>
             <h3>
                <span class="text">编辑用户</span>
             </h3>
        </div>
        <div class="box-in">
	        <form id="theForm" action="<s:url action="saveUser"/>">
				<input type="hidden" name="userForm.action_type" id="action_type" class="validate[required]" value='${userForm.action_type}'/>
				<input type="hidden" name="userForm.userId" id="action_type" class="validate[required]" value='${userForm.LOGIN_ID}'/>
	            <table border="0" cellspacing="0" cellpadding="0" class="table-03">
		            <tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         		姓名：
				         </td>
				         <td>
				         	<input type="text" name="userForm.userName" id="userName" class="input-style1 validate[required]" value='${userForm.userName}'/>&nbsp;<font color="red">*</font>
				         </td>
			   		</tr>
			   		<tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         		登录名：
				         </td>
				         <td>
				         	<input type="text" name="userForm.LOGIN_ID" id="LOGIN_ID" class="input-style1 validate[required]" value='${userForm.LOGIN_ID}' onkeyup="value=value.replace(/[\W]/g,'')" onkeydown="fncKeyStop(event)"onpaste="return false" oncontextmenu="return false"/>&nbsp;<font color="red">*</font>
				         </td>
			   		</tr>
			   		<tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         	 密码：
				         </td>
				         <td>
				         	<input type="password" name="userForm.password" id="password" class="input-style1 validate[required]" value='${userForm.password}'/>&nbsp;<font color="red">*</font>
				         </td>
			   		</tr>
			   		<tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         	 确认密码：
				         </td>
				         <td>
				         	<input type="password" name="userForm.confirmPassword" id="confirmPassword" class="input-style1 validate[required]" value='${userForm.password}'/>&nbsp;<font color="red">*</font>
				         </td>
			   		</tr>
			   		<tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         	 联系手机：
				         </td>
				         <td>
				         	<input type="text" name="userForm.telphone" id="telphone" class="input-style1 validate[required]" value='${userForm.telphone}'/>&nbsp;<font color="red">*</font>
				         </td>
			   		</tr>
			   		<tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         	 固定电话：
				         </td>
				         <td>
				         	<input type="text" name="userForm.local_phone" id="local_phone" value='${userForm.local_phone}'/>
				         </td>
			   		</tr>
			   		<tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         	 部门：
				         </td>
				         <td>
				         	<input type="hidden" name="userForm.DEPT_ID" id="DEPT_ID" class="input-style1 validate[required]" value='${dept.DEPT_ID}'/>
	    				 	<input type="text" name="dept.DEPT_NAME" id="DEPT_NAME" class="input-style1 validate[required]" value='${dept.DEPT_NAME}' readonly onclick="selectDept();"/>
				         </td>
			   		</tr>
			   		<tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         	 用户状态：
				         </td>
				         <td>
					         <select name="userForm.lockState" style="width:10%">
						         <s:if test='%{userForm.lockState.equals("0")}'>
						          <option value="0" selected>有效</option>
						          <option value="1">无效</option>
						         </s:if>
						         <s:else>
						          <option value="0">有效</option>
						          <option value="1" selected>无效</option>
						         </s:else>
					        </select>
				         </td>
			   		</tr>
			   		<tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         	 邮件地址：
				         </td>
				         <td>
				         	<input type="text" name="userForm.email" id="email" class="validate[required]" value='${userForm.email}'/>&nbsp;<font color="red">*</font>
				         </td>
			   		</tr>
			   		<tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         	 是否为白名单：
				         </td>
				         <td>
					         <select name="userForm.IS_VIP" style="width:10%">
						         <s:if test='%{userForm.IS_VIP.equals("1")}'>
						          <option value="1" selected>是</option>
						          <option value="0">否</option>
						         </s:if>
						         <s:else>
						          <option value="1">是</option>
						          <option value="0" selected>否</option>
						         </s:else>
					        </select>
				         </td>
			   		</tr>
			   		<tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         	 角色选择：
				         </td>
				         <td>
				         	  <select name="userForm.alreadySelect" id="alreadySelect" multiple="multiple" style="width:230px;">
							       	<s:iterator value="roleList" var="role">
							       		<s:if test='%{userForm.roleIds.contains(ROLE_ID)}'>
							           		<option value="<s:property value="#role.ROLE_ID"/>" selected><s:property value="#role.ROLE_NAME"/></option>
							           	</s:if>
							           	<s:if test='%{userForm.roleIds==null || !userForm.roleIds.contains(ROLE_ID)}'>
							           		<option value="<s:property value="#role.ROLE_ID"/>"><s:property value="#role.ROLE_NAME"/></option>
							           	</s:if>
							         </s:iterator>
						       </select>
				         </td>
			   		</tr>
			   		<tr>
			         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
			         	 岗位选择：
				         </td>
				         <td>
				         	  <select name="userForm.workGroupSelect" id="workGroupSelect" multiple="multiple" style="width:230px;">
							       	<s:iterator value="workGroupList" var="workGroup">
							       		<s:if test='%{userForm.workGroupIds.contains(WORKGROUP_ID)}'>
							           		<option value="<s:property value="#workGroup.WORKGROUP_ID"/>" selected><s:property value="#workGroup.WORKGROUP_NAME"/></option>
							           	</s:if>
							           	<s:if test='%{userForm.workGroupIds==null || !userForm.workGroupIds.contains(WORKGROUP_ID)}'>
							           		<option value="<s:property value="#workGroup.WORKGROUP_ID"/>"><s:property value="#workGroup.WORKGROUP_NAME"/></option>
							           	</s:if>
							         </s:iterator>
						       </select>
				         </td>
			   		</tr>
	            </table>
	            <div class="block03">
	                <input type="button" id="btn-save" class="btn-style02" value="保存"/>&nbsp;&nbsp;
		  			<input type="button" class="btn-style02" value="重置" onclick="resetForm()"/>&nbsp;&nbsp;
		  			<input type="button" class="btn-style02" value="返回"  onclick="back()" />
	       		</div>
	       	</form>
        </div>
</div>



</body>
	<script language="javascript">
		function back(){
			var deptId = $("input[name='userForm.DEPT_ID']").val();
			window.location.href="<s:url action='loadListUser.do?userForm.DEPT_ID="+deptId+"' namespace='/'/>";
		}
		function resetForm(){
			$('#theForm')[0].reset();
		}

        $('select[multiple]').each(function () {
            var height = $(this).children().size() * 18;
            $(this).height(height > 360 ? 360 : height);
        });
		
        $("#btn-save").click(function() {
        	if($("#password").val().length < 8 ) {
				alert("输入的密码不足8位！");
				return false;
			}   
        	if($("#password").val() != $("#confirmPassword").val()){
        		alert("两次输入的密码不一致，请重新输入");
        	}else if($("#alreadySelect").val()==null){
        		alert("请选择角色");
        	}else{
				$("#theForm").submit();
			}
		});
		$("#theForm").validationEngine().ajaxForm({
			type:"post",
			beforeSubmit:function() {
		        $("body").mask('正在保存,请稍后...');
			},
			success:function(data) {
				$("body").unmask();
				if (data == "true"){
					window.location.href="<s:url action='loadListUser' namespace='/'/>?userForm.DEPT_ID=${dept.DEPT_ID}";
				} else {
					alert(data);
				}
			},
			error:function(xhr){
				$("body").unmask();
			   alert(xhr);
			}
		});	
		
		function selectDept(){
			var selectDept = window.showModalDialog('<%=application.getContextPath()%>/loadDeptManage.do?type=select','选择部门','help:no;scroll:no;status:no;dialogHeight:600px;dialogWidth:900px');
	   		if(selectDept!=undefined){
	   			var id = "";
	   			var name = "";
	   			for (var one in selectDept){
                	id = id + selectDept[one].DEPT_ID + ",";
                	name = name + selectDept[one].DEPT_NAME + ",";
                	if(one>0){
                		alert('只能选择一个部门');
                		return false;
                	}
                }
                if(id.length>0){
                	id = id.substring(0,id.length-1);
                	name = name.substring(0,name.length-1);
                }
				$("#DEPT_ID").val(id);
				$("#DEPT_NAME").val(name);
			}
		} 
    </script>
</html>
